package com.mypackage.LocationPattern;

import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;

public class MainMenu extends Activity implements OnClickListener {
    private PendingIntent mAlarmSender;

	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
     // Create an IntentSender that will launch our service, to be scheduled
        // with the alarm manager.
        mAlarmSender = PendingIntent.getService(MainMenu.this,
                0, new Intent(MainMenu.this, LocationService.class), 0);

        setContentView(R.layout.main);
        
        
        
        View startLocationButton = findViewById(R.id.startLocation_button);
        startLocationButton.setOnClickListener(this);
        
        View stopLocationButton = findViewById(R.id.stopLocation_button);
        stopLocationButton.setOnClickListener(this);
        
        View saveLocationButton = findViewById(R.id.saveLocation_button);
        saveLocationButton.setOnClickListener(this);
        
        View sendDataButton = findViewById(R.id.sendData_button);
        sendDataButton.setOnClickListener(this);
        
        View showButton = findViewById(R.id.show_button);
        showButton.setOnClickListener(this);
        
    }
    
    public void onClick(View v){
    	switch (v.getId()){
    	case R.id.startLocation_button:
    		// We want the service started every hour
            long firstTime = SystemClock.elapsedRealtime();

            // Schedule the alarm!
            AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
            am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                            firstTime, 3600*1000, mAlarmSender);

            // Tell the user about what we did.
            Toast.makeText(MainMenu.this, R.string.service_started,
                    Toast.LENGTH_LONG).show();
    	case R.id.stopLocation_button:
    		// And cancel the alarm.
            AlarmManager am2 = (AlarmManager)getSystemService(ALARM_SERVICE);
            am2.cancel(mAlarmSender);

            // Tell the user about what we did.
            Toast.makeText(MainMenu.this, R.string.service_stopped,
                    Toast.LENGTH_LONG).show();
    	case R.id.saveLocation_button:
    	case R.id.sendData_button:
    	case R.id.show_button:
    		Intent i = new Intent(this, TestCaseDisplay.class);
    		startActivity(i);
    		break;
    	}
    }
    
    
}